<template>
	<view>
		<view class="cu-modal" :class="showMolde?'show':'hide'">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">请输入密码</view>
				</view>
				<view class="padding-xl">
					<view class="padding20rpx border1">
						<input class="inpt" placeholder="请输入密码" @input="inputTyping" confirm-type="done" 
						 v-model="PassWord"></input>
					</view>
				</view>
				<view class="cu-bar bg-white">
					<view class="action margin-0 flex-sub text-red solid-right" @tap="hideModal(0)">取消</view>
					<view class="action margin-0  flex-sub  text-blue solid-left" @tap="hideModal(1)">修改密码</view>
					<view class="action margin-0  flex-sub  text-blue solid-left" @tap="hideModal(2)">确定</view>
				</view>

			</view>
		</view>


		<view class="header margin-top">
			<view class="line"></view>
			<view class="header-contant" style="display: flex;">
				<view class="title1">设置内容</view>
				<view class="title2" style="float: right;">开启状态</view>
			</view>

		</view>
		<view class="block margin-top">
			<view class="cu-form-group" v-for="(item,index) in items" :key="item.value">
				<text class="title">{{item.SystemName}}</text>
				<jiuaiCheckbox @change='changeBox' :index="index" :value="item.Value" :checked="item.Value!=0"></jiuaiCheckbox>
			</view>
		</view>
	</view>
</template>

<script>
	import * as Api from '@/syApis/sySet/sySet.js'
	import jiuaiCheckbox from "@/components/jiuai-checkbox.vue";
	export default {
		data() {
			return {
				PassWord: '',
				showMolde: true,
				focuspw: true,
				items: [
					// {
					// 	value: '是否允许负库存出库',
					// 	name: '是否允许负库存出库',
					// 	checked: false
					// },
					// {
					// 	value: '单据是否直接审核',
					// 	name: '单据是否直接审核',
					// 	checked: false
					// },
					// {
					// 	value: '开启批号管理',
					// 	name: '开启批号管理',
					// 	checked: false
					// },
					// {
					// 	value: '售价低于进价提示',
					// 	name: '售价低于进价提示',
					// 	checked: true
					// },
					// {
					// 	value: '是否跟踪往来单位最近单价',
					// 	name: '是否跟踪往来单位最近单价',
					// 	checked: true
					// }
				]
			}
		},
		components: {
			jiuaiCheckbox
		},
		created() {
			this.getSystemSettingInfo();
		},
		methods: {
			//获取系统设置信息
			getSystemSettingInfo() {
				let data = {};
				var that = this;
				Api.Select_SystemSetup(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "No connection could be made because the target machine actively refused it") {

						} else if (res.data.ErrorMsg != "") {

						} else {
							// //console.tablele(res.data.ResultMsg);
							//赋值数组
							that.items = res.data.ResultMsg;

						}
					} else {

					}
				})
			},
			changeBox(e) {
				console.log(e)
				let state = e.detail.value;
				let selectIndex = e.detail.index;
				if (state == true) {
					this.items[selectIndex].State = false;
				} else {
					this.items[selectIndex].State = true;
				}
				// console.log(this.items[selectIndex].State)
				let data = {
					SystemName: this.items[selectIndex].SystemName,
					// Value:this.items[selectIndex].State
					// if(State ==true){
					// 	this.items[selectIndex].Value =1
					// }else{
					// 	this.items[selectIndex].Value =0
					// }
					Value: this.items[selectIndex].State ? 1 : 0

				};
				var that = this;
				Api.Save_SystemSetup(data, function(res) {
					console.log(res)
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {

						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							uni.setStorageSync("SystemName", that.SystemName);
							uni.setStorageSync("Value", that.Value);
							
						}
					} else {
						Api.showTip("服务器超时");
					}
				})
			},
			// 			changeBox(e) {
			// 				let data = {};
			// 				var that = this;
			// 				Api.Save_SystemSetup(data, function(res) {
			// 					if (res.state) {
			// 						if (res.data.ErrorMsg == "获取登录信息失败") {
			// 
			// 						} else if (res.data.ErrorMsg != "") {
			// 
			// 						} else {
			// 							//console.tablele(e);
			// 							//获取当前的选项状态
			// 							let state = e.detail.value;
			// 							//当前点击的索引
			// 							let selectIndex = e.detail.index;
			// 							if (state == 0) {
			// 								this.items[selectIndex].Value = 1;
			// 							} else {
			// 								this.items[selectIndex].Value = 0;
			// 							}
			// 							//console.tablele(res.data.ResultMsg);
			// 
			// 						}
			// 					} else {
			// 
			// 					}
			// 					//console.tablele(res.data.ResultMsg);
			// 				})
			// 				// uni.setStorageSync("Value", this.items[selectIndex].Value);
			// 
			// 			},
			inputTyping(e) {
				this.PassWord = e.detail.value
				console.log(this.PassWord)
			},
			hideModal(state) {
				// console.log(state)
				if (state == 0) {
					uni.navigateBack({
						delta: 1
					})
				}
				if (state == 1) {
					uni.navigateTo({
						url: "./swtpw"
					})
				}
				if (state == 2) {
					if (this.PassWord.length == 0) {
						Api.showTip("密码不能为空");
						// this.showMolde = true
					} else {
						var that = this;
						let data = {
							PassWord: this.PassWord
						};
						Api.Gain_AdminPassword(data, function(res) {
							if (res.state) {
								if (res.data.ErrorMsg == '获取登录信息失败') {

								} else if (res.data.ErrorMsg != "") {
									Api.showTip(res.data.ErrorMsg);
								} else {
									if (res.data.TipsMsg == 'OK') {
										// Api.showTip("密码设置成功");
										that.showMolde = false;
									}

								}
							} else {
								Api.showTip("服务器超时");
							}
						});
					}
					// uni.setStorageSync("PassWord",this.PassWord);
					// log(this.PassWord);
				}
			},
			// #ifndef MP
			onNavigationBarButtonTap(e) {
				// const index = e.index;
				// console.log(e)
				let data = {};
				var that = this;
				Api.Save_SystemSetup(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "获取登录信息失败") {

						} else if (res.data.ErrorMsg != "") {

						} else {
							//console.tablele(res.data.ResultMsg);
							for (let item in this.items) {

							}

						}
					} else {
						Api.showTip("服务器超时");
					}
					// //console.tablele(res.data.ResultMsg);
				})


			},
			// #endif
		}
	}
</script>

<style>
	.header {
		background-color: #ffffff;
		padding: 0.5px 15px;
		display: -webkit-box;
		display: -webkit-flex;
		display: -ms-flexbox;
		display: flex;
	}

	.header-contant {
		display: flex;
		width: 100%;
		justify-content: space-between
	}

	.title1 {
		text-align: justify;
		padding-right: 15px;
		font-size: 15px;
		position: relative;
		min-height: 30px;
		line-height: 30px;
	}

	.title2 {
		font-size: 15px;
		position: relative;
		min-height: 30px;
		line-height: 30px;
	}

	.line {
		width: 5px;
		background-color: rgba(124, 170, 216, 1);
		position: relative;
		/* min-height: 19px;
		line-height: 18px; */
		margin-right: 10px;
	}
</style>
